//
//  WeiboContentCell.swift
//  WeiBo test
//
//  Created by Aquarius_wing on 16/5/6.
//  Copyright © 2016年 Wing. All rights reserved.
//

import UIKit
import SnapKit

let cellMargin:CGFloat=10
class WeiboContentCell: UITableViewCell {
    var height:CGFloat!
//    var weiboContent:WeiboContent?{
//        didSet{
//            self.iconImageView.sd_setImageWithURL(weiboContent?.headImageURL)
//            self.nameLabel.text=weiboContent?.name
//            self.contentLabel.text=weiboContent?.text
//            separatView.backgroundColor=UIColor.grayColor()
//            
//            if weiboContent?.pic_urls!.count != 0{
//                contentImageView=ContentImageView(pics: (weiboContent?.pic_urls)!)
//                print("contentImageView.subviews.count",contentImageView.subviews.count)
//            }
//        }
//    }
    //懒加载控件
    private lazy var originalView: OriginalView = OriginalView()
    
    private lazy var bottomView: BottomView = BottomView()
    
    //原创微博底部约束  用来记录底部约束  后续根据是否有配图 来动态修改
    var bottomConstraints: Constraint?
    
    var weiboContent:WeiboContent?{
        didSet{
            
            originalView.weiboContent=weiboContent
//            self.bottomConstraints?.uninstall()
            
        }
    }

//    func setFrame(){
//        //设置iconImageView
//        self.iconImageView.frame = CGRect(x: 10, y: 10, width: 50, height: 50)
//        //设置nameLabel
//        self.nameLabel.frame.origin=CGPoint(x: CGRectGetMaxX((self.iconImageView.frame))+10, y: 10)
//        self.nameLabel.frame.size=setSize(NSString(string: self.nameLabel.text!), maxSize: CGSizeMake(CGFloat(MAXFLOAT), 20), attributes: [NSFontAttributeName:self.nameLabel.font])
//        //设置contentLabel
//        self.contentLabel.numberOfLines=0
//        self.contentLabel.frame.origin=CGPoint(x: 10, y: CGRectGetMaxY(self.iconImageView.frame)+10)
//        self.contentLabel.frame.size=setSize(NSString(string: self.contentLabel.text!), maxSize: CGSizeMake( SCREENSIZE.width-15,CGFloat(MAXFLOAT)), attributes: [NSFontAttributeName:self.contentLabel.font])
//        //设置图片
//        self.contentImageView.frame.origin=CGPoint(x: 0, y: CGRectGetMaxY(self.contentLabel.frame)+10)
//        let countImg=self.contentImageView.subviews.count
//        if countImg == 0{
//            self.contentImageView.frame.size=CGSizeZero
//        }else if countImg == 1{
//            self.contentImageView.frame.size=CGSizeMake(SCREENSIZE.width*0.8, SCREENSIZE.width*0.8)
//        }else{
//            self.contentImageView.frame.size=CGSizeMake(SCREENSIZE.width, SCREENSIZE.width/3*CGFloat(countImg-1/3+1))
//        }
//        //设置隔离区
//        self.separatView.frame=CGRect(x: 0, y: CGRectGetMaxY(self.contentImageView.frame), width: SCREENSIZE.width, height: 10)
//        
//        
//        self.addSubview(self.iconImageView)
//        self.addSubview(self.nameLabel)
//        self.addSubview(self.contentLabel)
//        self.addSubview(self.contentImageView)
//        self.addSubview(self.separatView)
//        height=CGRectGetMaxY(self.separatView.frame)
//    }
    
    
    //初始化
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier!)
        
        setupUI()
//        print("height",height)
//        weiboContent?.height=height
    }
    func setupUI(){
        //添加子视图
        contentView.addSubview(originalView)
        contentView.addSubview(bottomView)
        
        //设置约束信息
        originalView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentView.snp_top)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
        }
        
        
        //设置约束
        bottomView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView.snp_left)
            self.bottomConstraints = make.top.equalTo(originalView.snp_bottom).constraint
            make.right.equalTo(contentView.snp_right)
            make.height.equalTo(40)
        }
        
        //容器视图的底部约束 是自动计算行高关键
        contentView.snp_makeConstraints { (make) -> Void in
            //contentView 底部约束 是最关键的一点
            make.bottom.equalTo(bottomView.snp_bottom)
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setSize(text:NSString,maxSize:CGSize,attributes:[String : AnyObject]?)->CGSize{
        return text.boundingRectWithSize(maxSize, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attributes, context: nil).size
    }
//    //MARK: 懒加载控件
//    lazy var iconImageView:UIImageView=UIImageView(image: UIImage(named: "avatar_default_big"))
//    lazy var nameLabel:UILabel=UILabel(title: "我就是杜蕾他哥", size: 14, color: UIColor.darkGrayColor())
//    lazy var contentLabel:UILabel=UILabel(title: "野内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮内心的攻城狮", size: 14, color: UIColor.lightGrayColor(),margin: 14)
//    lazy var contentImageView:ContentImageView=ContentImageView()
//    lazy var separatView:UIView=UIView()

}

